package org.jeecg.config.filter;


import org.springframework.context.annotation.Configuration;


import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;

/**
 * 过滤emoji的filter
 */
@Slf4j
public class EmojiFilter implements Filter{

    private static final String POST = "POST";
    private static final String PUT = "PUT";

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;

        if (!request.getMethod().equals(POST) && !request.getMethod().equals(PUT)) {
            return;
        }
        log.info("EmojiFilter-doFilter==========in");
        EmojiWrapper requestWrapper = new EmojiWrapper(request);
        chain.doFilter(requestWrapper, response);
    }
    @Override
    public void destroy() {

    }
}

